
package com.kugou.game.sdk.base;

import com.kugou.framework.base.BaseFragmentActivity;
import com.kugou.game.sdk.api.common.ActivityOrientation;
import com.kugou.game.sdk.api.common.IEventCode;
import com.kugou.game.sdk.core.PlatformEventDispatcher;
import com.kugou.game.sdk.core.SDKControler;
import com.kugou.game.sdk.utils.Rx;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.WindowManager;

/**
 * 描述:SDK界面基类
 * 
 * @author chenys
 * @since 2013-12-5 下午2:54:39
 */
public abstract class BaseSDKFragmentActivity extends BaseFragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SDKControler.activityCreate();
        if (SDKControler.isInitialize()) {
            setTheme(Rx.style.kg_SdkTheme);
            if (SDKControler.isFullScreen()) {
                // 设置全屏
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            if (SDKControler.getActivityOrientation() == ActivityOrientation.PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            } else {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        } else {
            throw new RuntimeException("sdk还没有初始化.");
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SDKControler.activityDestory();
        if (SDKControler.getActivityCounter() == 0) {
            PlatformEventDispatcher.sendEvent(IEventCode.GO_BACK_TO_GAME, null);
        }
    }
}
